// CityInfo.cpp: implementation of the CCityInfo class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "GameCore.h"
#include "CityInfo.h"
#include "Xml.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCityInfo::CCityInfo()
{
	m_strXmlFilePath=g_lpCommFunc->GetFilePathByUser(_T("Config\\CTInfo.xml"));
}

CCityInfo::~CCityInfo()
{

}

void CCityInfo::LoadCities()
{
	m_arrCityInfos.RemoveAll();
	CXml xml;
	xml.LoadXml(m_strXmlFilePath);
	CXmlNode CityNode=xml.GetNodeList(_T("//Citys/City"));
	CXmlNode NPCNode;
	while(CityNode.GetNextNode())
	{
		BackCityInfo info;
		CString strTemp=CityNode.GetAttribute(_T("ID"));
		info.m_ID=_ttol(strTemp);
		strTemp=(CityNode.GetAttribute(_T("Name")));
		_tcscpy(info.m_tcName,strTemp.GetBuffer(40));
		NPCNode=CityNode.GetNodeList(_T("NPC")); 
		int i=-1;
		while(NPCNode.GetNextNode() && i<20)
		{
			i++;
			info.m_posPose[i].x=_ttol(NPCNode.GetAttribute(_T("X")));
			info.m_posPose[i].y=_ttol(NPCNode.GetAttribute(_T("Y")));
			info.m_posPose[i].z=_ttol(NPCNode.GetAttribute(_T("Z")));
		}
		m_arrCityInfos.Add(info);
	}
}

BOOL CCityInfo::GetCityByID(int CityID,BackCityInfo& info)
{
	int iSize=m_arrCityInfos.GetSize();
	for(int i=0;i<iSize;i++)
	{
		if(m_arrCityInfos[i].m_ID==CityID)
		{
			info=m_arrCityInfos[i];
			return TRUE;
		}
	}
	return FALSE;
}